package test.lx.com.view_qualify;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    private Button btn_submit;
    private Button btn_refresh;
    private EditText ed_input;
    private TextView mShowPassViwe;
    private CheckView checkView;

    int []checkNum=null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
    }

    private void initData() {
        checkNum=CheckUtils.getCheckNum();
        checkView.setCheckNum(checkNum);
        checkView.invaliChenkNum();

    }

    private void initView() {
        mShowPassViwe= (TextView) this.findViewById(R.id.tv_tips);
        btn_submit= (Button) this.findViewById(R.id.btn_submit);
        btn_refresh = (Button) this.findViewById(R.id.btn_refresh);
        ed_input= (EditText) this.findViewById(R.id.ed_input);
        checkView= (CheckView) this.findViewById(R.id.checkView);
        btn_submit.setOnClickListener(this);
        btn_refresh.setOnClickListener(this);


    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_submit:
                String userInput = ed_input.getText().toString();
                if(CheckUtils.checkNum(userInput, checkNum)){
                    setPassString("通过");
                    Toast.makeText(this, "通过", Toast.LENGTH_SHORT).show();
                }else{
                    setPassString("未通过");
                    Toast.makeText(this, "未通过", Toast.LENGTH_SHORT).show();
                }
                break;
            case R.id.btn_refresh:
                initData();
                break;
        }
    }
    public void setPassString(String passString) {
        mShowPassViwe.setText(passString);
    }
}
